define(function(require, exports, module) {
    //首页-banner轮播图
    exports.mainPhoto = function(){
        var $ul        = $('.carousel>ul'),
            $li        = $ul.find("li"),
            $leftIcon  = $('.carousel').find('.photo_left_icon'),
            $rightIcon = $('.carousel').find('.photo_right_icon'),
            $left      = parseInt($ul.css('left')),
            $len       = $li.length,
            $dotIcon   = $('.carousel-btn-list i'),
            index;
        //滚动轮播图
        function MPdata($left,direction) {
            $ul = $('.carousel>ul');
            $li = $ul.find("li");
            var $maxwidth = -(990 * $len);
            index = -($left / 990);
            $dotIcon.removeClass('selected').eq(index).addClass('selected');
            if($left==0&&direction=="right"){
                $(".js-temporary").remove();
                $ul.append("<li class='js-temporary'>"+$li.eq(0).html()+"</li>");
                $ul.stop().animate({left: $maxwidth},function(){
                    $ul.css("left",0);
                    $(".js-temporary").remove();
                });
                return;
            }else if($left==($maxwidth+990)&&direction=="left"){
                $(".js-temporary").remove();
                $ul.prepend("<li class='js-temporary'>"+$li.eq($len-1).html()+"</li>");
                $ul.css("left",-990);
                $ul.stop().animate({left: 0},function(){
                    $ul.css("left",$maxwidth+990);
                    $(".js-temporary").remove();
                });
                return;
            }else{
                $ul.stop().animate({left: $left});
            };
        };
        //左击按扭
        $leftIcon.click(function () {
            if($('.carousel>ul').is(":animated")){ return;};
            $left = $left + 990;
            if ($left > 0) {
                $left = -(990 * ($len - 1));
            };
            MPdata($left,"left");
        });
        //右击按扭
        $rightIcon.click(function () {
            if($('.carousel>ul').is(":animated")){ return;};
            $left = $left - 990;
            if ($left <= -( 990 * $len)) {
                $left = 0;
            };
            MPdata($left,"right");
        });
        //点击轮播圆点
        $dotIcon.click(function () {
            var index = $(this).index();
            $dotIcon.removeClass('selected').eq(index).addClass('selected');
            $left = -((index) * 990);
            MPdata($left);
        });
        //时间调用方法
        function num() {
            $left = $left - 990;
            if ($left <= -(990 * $len)) {
                $left = 0;
            }
            MPdata($left,"right");
        };
        var $time = setInterval(function(){
            num();
        },4000);
        //停止时间事件
        $('.carousel>ul,.photo_left_icon,.photo_right_icon').mouseover(function () {
            clearInterval($time);
        });
        //继续时间事件
        $li.mouseout(function () {
            $time = setInterval(function(){
                num();
            }, 4000);
        });
    };
    //首页-推荐信息的轮播图
    exports.recommend = function(){
        //move info
        $(".recommend-product>i").on("click",function(){
            if($('.recommend-product>ul').is(":animated")){ return;};
            var $box  = $(".recommend-product").find("ul"),
                $size = parseInt($box.css("left")),
                $num  = $box.find("li").length;
            SpecialScroll(-$size/705,$(this).attr("icon"),$num);
        });
        //time start
        var SpecialScrolltime = setInterval(function(){
            for(var i=0;i<$(".company").length;i++){
                var $box  = $(".recommend-product").find("ul"),
                    $size = parseInt($box.css("left")),
                    $num  = $box.find("li").length;
                SpecialScroll(-$size/705,"right",$num);
            };
        },5000);
        //end
        $('.recommend-product').mouseover(function () {
            clearInterval(SpecialScrolltime);
        });
        //start
        $('.recommend-product').mouseout(function () {
            SpecialScrolltime = setInterval(function(){
                for(var i=0;i<$(".company").length;i++){
                    var $box  = $(".recommend-product").find("ul"),
                        $size = parseInt($box.css("left")),
                        $num  = $box.find("li").length;
                    SpecialScroll(-$size/705,"right",$num);
                }
            },5000);
        });
        function SpecialScroll($len,$icon,$num){
            $icon=="left"?$len--:$len++;
            if($len<0){
                $len=$num-1;
            }else if($len==$num){
                $len=0;
            };
            $(".recommend-product").find("ul").stop(true,true).animate({left:$len*-705},500);
        };
    };
    //常规图片滚动图
    exports.general = function(){
        //定时调用
        if($(".company").find("li").length>6){
            var $scrollEnvironment = setInterval(function(){
                for(var i=0;i<$(".company").length;i++){
                    environment($(".company").eq(i).find("ul"),$(".company").eq(i).find("li").length);
                };
            },20);
        };
        //end
        $('.company,.alert-bg,.photo-module').mouseover(function () {
            clearInterval($scrollEnvironment);
        });
        //start
        $('.company,.alert-bg,.photo-module').mouseout(function () {
            $scrollEnvironment = setInterval(function(){
                for(var i=0;i<$(".company").length;i++){
                    environment($(".company").eq(i).find("ul"),$(".company").eq(i).find("li").length);
                };
            },20);
        });
        //move event
        $("body").delegate(".company li img",{
            mousemove:function(event){
                var $boxLeft = $(".company").offset().left,
                    $boxTop  = $(".company").offset().top,
                    $Mleft   = (event.pageX)-$boxLeft+10,
                    $Mtop    = (event.pageY)-$boxTop-5;
                $Mleft>877?$Mleft=(event.pageX)-$boxLeft-120:$Mleft;
                $Mtop>102?$Mtop=102:$Mtop;
                $(this).parents(".company").find(".large-buttons").css({
                    display : "block",
                    left    : $Mleft,
                    top     : $Mtop
                });
            },
            mouseleave:function(){
                $(".large-buttons").hide();
            }
        });
        //open big photo
        $(".company").find("li").on("click",function(){
            $(this).addClass("js-company-show");
            $(".photo-module,.alert-bg").show(500);
            var $src = $(this).find("img").attr("src");
            $src = $src.replace("_150X110","");
            $(".js-module-item").html("<img src="+$src+" alt='趋数网络科技有限公司－优美的环境'>");
            var $val,
                $H = $(window).height();
            $("body").scrollTop() > 0 ? $val = $("body").scrollTop() : $val = $("html").scrollTop();
            $H>$val?$val+=50:$val+=10;
            $(".photo-module").css({top:$val});
        });
        //function
        function environment($box,$len){
            var $left = parseInt($box.css("left"));
            if($left==-170){
                var $html = $box.find("li").eq(0).html();
                $box.find("li").eq(0).insertAfter($box.find("li").eq($len-1));
                $box.css({left:0});;
            }else{
                $box.css("left",$left-1);
            };
        };
    };
    //弹框切换图片
    exports.changePhoto = function(){
        //弹框层-上一张照片
        $(".photo-module").find(".photo_left_icon").on("click",function(){
            changePhoto("left");
        });
        //弹框层-下一张照片
        $(".photo-module").find(".photo_right_icon").on("click",function(){
            changePhoto("right");
        });
        $(document).on("keydown",function(e){
            if($(".photo-module").css("display")=="block"){
                var $key = e.keyCode;
                if($key==37){
                    changePhoto("left");
                }else if($key==39){
                    changePhoto("right");
                }else if($key==27){
                    $(".photo-module,.alert-bg").hide(500);
                };
            };
        });
        //切换弹框图片
        function changePhoto(direction){
            var $item = $(".js-company-show"),
                $src;
            if(direction=="left"){
                //往左切换图片
                $src = $item.prev().find("img").attr("src");
                if($src){
                    $item.removeClass("js-company-show").prev().addClass("js-company-show");
                }else{
                    $src = $item.closest("ul").find("li").last().find("img").attr("src");
                    $item.removeClass("js-company-show").closest("ul").find("li").last().addClass("js-company-show");
                };
            }else if(direction=="right"){
                $src = $item.next().find("img").attr("src");
                if($src){
                    $item.removeClass("js-company-show").next().addClass("js-company-show");
                }else{
                    $src = $item.closest("ul").find("li").first().find("img").attr("src");
                    $item.removeClass("js-company-show").closest("ul").find("li").first().addClass("js-company-show");
                };

            };
            $src = $src.replace("_150X110","");
            $(".js-module-item").html("<img src='"+$src+"' alt='趋数网络科技有限公司-图片'>");
            $(".js-module-item").css("opacity","0.8").stop().animate({opacity:1},500);
        };
    };
    //常规图片滚动图
    exports.smallPhoto = function(){
        //定时调用
        if($(".scroll-partner").find("li").length>5){
            var $scrollPartner = setInterval(function(){
                scrollPartner();
            },20);
        };
        //end
        $('.scroll-partner').mouseover(function () {
            clearInterval($scrollPartner);
        });
        //start
        $('.scroll-partner').mouseout(function () {
            $scrollPartner = setInterval(function(){
                scrollPartner();
            },20);
        });
        //function
        function scrollPartner(){
            var $box  = $(".scroll-partner").find("ul"),
                $left = parseInt($box.css("left"));
            if($left==-91){
                var $html = $box.find("li").eq(0).html();
                $box.find("li").eq(0).remove();
                $box.append("<li>"+$html+"</li>").css({left:0});;
            }else{
                $box.css("left",$left-1);
            };
        };
    };
    //上下移动
    exports.unDownCarousel = function(){
        //关于微信-文本向上移动
        $("#main").delegate(".scrolltop-icon",{
            mouseover:function(){
                var $infoBox = $(this).siblings(".scrolltext-box"),
                    $top     = parseInt($infoBox.css("margin-top")),
                    $scroll  = setInterval(function(){
                        if($top==0){
                            clearInterval($scroll);
                            return;
                        }else{
                            $top+=1;
                            $infoBox.css({marginTop:$top+1});
                        };
                    },10);
                $(this).mouseout(function(){
                    clearInterval($scroll);
                });
            }
        });
        //关于微信-文本向下移动
        $("#main").delegate(".scrollbottom-icon",{
            mouseover:function(){
                var $infoBox = $(this).siblings(".scrolltext-box"),
                    $top     = parseInt($infoBox.css("margin-top")),
                    $infoH   = $infoBox.height(),
                    $boxH    = $(this).parent().height();
                var $scroll  = setInterval(function(){
                    if($top==-($infoH-$boxH)){
                        clearInterval($scroll);
                        return;
                    }else{
                        $top-=1;
                        $infoBox.css({marginTop:$top});
                    };
                },10);
                $(this).mouseout(function(){
                    clearInterval($scroll);
                });
            }
        });
        //关于微信-趋数活动-滚动效果
        $("#main").delegate(".scroll-details-nav li",{
            click:function(){
                $(this).addClass("selected").siblings().removeClass("selected")
                var index    = $(this).index();
                HorizontalScroll(index);
            }
        });
        //关于微信-趋数活动-上移滚动效果
        $("#main").delegate(".scroll-details .scrolltop-icon",{
            click:function(){
                var index = parseInt($(".scroll-details-nav").find(".selected").removeClass("selected").next().addClass("selected").attr("num"));
                if(!index){
                    index=0;
                    $(".scroll-details-nav").find("li").eq(index).addClass("selected").siblings().removeClass("selected");
                };
                HorizontalScroll(index);
            }
        });
        //关于微信-趋数活动-下移移滚动效果
        $("#main").delegate(".scroll-details .scrollbottom-icon",{
            click:function(){
                var index = parseInt($(".scroll-details-nav").find(".selected").removeClass("selected").prev().addClass("selected").attr("num"));
                if(!index&&index!=0){
                    index=$(".scroll-details-nav").find("li").length-1;
                    $(".scroll-details-nav").find("li").eq(index).addClass("selected").siblings().removeClass("selected");
                };
                HorizontalScroll(index);
            }
        });
        //关于微信-趋数活动-定时自动滚动效果
        var $HorizontalScroll = setInterval(function(){
            var index = parseInt($(".scroll-details-nav").find(".selected").removeClass("selected").next().addClass("selected").attr("num"));
            if(!index){
                index=0;
                $(".scroll-details-nav").find("li").eq(index).addClass("selected").siblings().removeClass("selected");
            };
            HorizontalScroll(index);
        },5000);
        //关于微信-趋数活动-定时自动滚动效果停止
        $('.scroll-details').mouseover(function () {
            clearInterval($HorizontalScroll);
        });
        //关于微信-趋数活动-定时自动滚动效果开始
        $('.scroll-details').mouseout(function () {
            $HorizontalScroll = setInterval(function(){
                var index = parseInt($(".scroll-details-nav").find(".selected").removeClass("selected").next().addClass("selected").attr("num"));
                if(!index){
                    index=0;
                    $(".scroll-details-nav").find("li").eq(index).addClass("selected").siblings().removeClass("selected");
                };
                HorizontalScroll(index);
            },5000);
        });
        //关于微信-趋数活动-定时自动滚动闭包
        function HorizontalScroll(index){
            var $thistop = -(index*40);
            $(".scroll-details-nav").find("ul").stop().animate({top:$thistop},1000);
            $(".scroll-details-content").find("li").stop().animate({top:index*-277},1000);
        };
    };
});